<?php

class HTML_Select extends HTML implements HTMLElements  {
	
	private $attributeDisabled;
	private $attributeMultiple;
	private $attributeSize;
	private $attributeName;
	
	const HTML_SELECT = 'select';
	
	
	const DISABLED_DISABLED = 'disabled=""';
	const DISABLED_ENABLED = '';
	const ATTRIBUTE_DISABLED = 'disabled';
	const ATTRIBUTE_MULTIPLE = 'multiple';
	const ATTRIBUTE_SIZE = 'size';
	const ATTRIBUTE_NAME = 'name';
	
	/**
	 * 
	 * This function creates a complete Link-Element.
	 * The attributes have to be passed within an array. Possible attributes are:
	 * 	- $class
	 * 	- $id
	 * 	- $title
	 * @param unknown_type $parent
	 * @param String[][] $properties
	 */
	public function __construct($parent, $properties)  {
		PropertySetter::setProperties($this, $properties);
		$parent->addChildElement($this);
	}
	
	public function setAttributeDisabled ($disabled)  {
		$this->attributeDisabled = $disabled;
	}
	
	public function setAttributeMultiple ($multiple)  {
		$this->attributeMultiple = $multiple;
	}
	
	public function setAttributeSize ($size)  {
		$this->attributeSize = $size;
	}
	
	public function setAttributeName ($name)  {
		$this->attributeName = $name;
	}
	
	public function getAttributeDisabled ()  {
		return $this->attributeDisabled;
	}
	
	public function getAttributeMultiple ()  {
		return $this->attributeMultiple;
	}
	
	public function getAttributeSize ()  {
		return $this->attributeSize;
	}
	
	public function getAttributeName ()  {
		return $this->attributeName;
	}
	
	public function getSelectAttributes ()  {
	
		$output = '';
	
		if (!empty($this->attributeDisabled))  {
			$output .= $this->getAttributeDisabled();
		}
		
		if (!empty($this->attributeMultiple))  {
			$output .= ' '. self::ATTRIBUTE_MULTIPLE. '="'. $this->getAttributeMultiple(). '"';
		}
		
		if (!empty($this->attributeSize))  {
			$output .= ' '. self::ATTRIBUTE_SIZE. '="'. $this->getAttributeSize(). '"';
		}
		
		if (!empty($this->attributeName))  {
			$output .= ' '. self::ATTRIBUTE_NAME. '="'. $this->getAttributeName(). '"';
		}
	
		if ($output == '')  {
			$output = ' ';
		}
	
		return $output;
	}
	
	public static function getAttributes ()  {
		$attributes = array();
		$parentAttributes = parent::getAttributes();
		$attributes[] = self::ATTRIBUTE_DISABLED;
		$attributes[] = self::ATTRIBUTE_MULTIPLE;
		$attributes[] = self::ATTRIBUTE_SIZE;
		$attributes[] = self::ATTRIBUTE_NAME;
		return array_merge($parentAttributes, $attributes);
	}
	
	public function toString ()  {
		
		$output = '<'. self::HTML_SELECT.
					$this->getHTMLAttributes().
					$this->getSelectAttributes(). '>';
		
		if($this->getChildElements())  {
			foreach ($this->getChildElements() as $element)  {
				$output .= $element->toString();
			}
		}
		
		$output .= '</'. self::HTML_SELECT. '>';
		
		return $output;
	}
	
}